package com.jy.adscm.spss.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.spss.bean.HcCupweldingrecord;
import com.jy.adscm.spss.service.HcCupweldingrecordService;
import com.jy.adscm.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyy
 * @since 2018-11-20
 */
@RestController
@RequestMapping("hcCupweldingrecord")
public class HcCupweldingrecordController {
    @Autowired
    HcCupweldingrecordService hcCupweldingrecordService;
    @RequestMapping("insertrecord")
    public SimpleCoreResponse insertrecord( HcCupweldingrecord record) throws AdscmSystemException {
        record.setId(UUID.randomUUID().toString());
        if (record.getQrrq().equals("")){
            record.setQrrq(null);
        }
        if (record.getRq1().equals("")){
            record.setRq1(null);
        }
        if (record.getRq2().equals("")){
            record.setRq2(null);
        }
        if (record.getRq3().equals("")){
            record.setRq3(null);
        }
        if (record.getGzsjd1().equals("")){
            record.setGzsjd1(null);
        }
        if (record.getGzsjd2().equals("")){
            record.setGzsjd2(null);
        }
        if (record.getGzsjd3().equals("")){
            record.setGzsjd3(null);
        }
        if (record.getGzsjd4().equals("")){
            record.setGzsjd4(null);
        }
        if (record.getGzsjd5().equals("")){
            record.setGzsjd5(null);
        }
        if (record.getGzsjd6().equals("")){
            record.setGzsjd6(null);
        }
        if(record.getSixrq1().equals("")){
            record.setSixrq1(null);
        }
        if(record.getSixrq2().equals("")){
            record.setSixrq2(null);
        }
        if(record.getSixrq3().equals("")){
            record.setSixrq3(null);
        }

        if(record.getSixdate1().equals("")){
            record.setSixdate1(null);
        }
        if(record.getSixdate2().equals("")){
            record.setSixdate2(null);
        }
        if(record.getSixdate3().equals("")){
            record.setSixdate3(null);
        }
        if ( "".equals( record.getJlrrq())){
            record.setJlrrq(null);
        }
        if ("".equals(record.getXcxjyrq())){
            record.setXcxjyrq(null);
        }
        if("".equals(record.getDate1())){
            record.setDate1(null);
        }
        return new SimpleCoreResponse("200","成功添加数据",hcCupweldingrecordService.insert(record));
    }

    @RequestMapping("deleteRecord")
    public SimpleCoreResponse deleteRecord(HcCupweldingrecord record) throws AdscmSystemException {
        return new SimpleCoreResponse("200","成功删除数据",hcCupweldingrecordService.deleteById(record.getId()));
    }

    @RequestMapping("updateRecord")
    public SimpleCoreResponse updateRecord(HcCupweldingrecord record) throws AdscmSystemException {
        System.out.println(record.getRetreatingNum1());
        if (record.getQrrq().equals("")){
            record.setQrrq(null);
        }
        if (record.getRq1().equals("")){
            record.setRq1(null);
        }
        if (record.getRq2().equals("")){
            record.setRq2(null);
        }
        if (record.getRq3().equals("")){
            record.setRq3(null);
        }
        if (record.getGzsjd1().equals("")){
            record.setGzsjd1(null);
        }
        if (record.getGzsjd2().equals("")){
            record.setGzsjd2(null);
        }
        if (record.getGzsjd3().equals("")){
            record.setGzsjd3(null);
        }
        if (record.getGzsjd4().equals("")){
            record.setGzsjd4(null);
        }
        if (record.getGzsjd5().equals("")){
            record.setGzsjd5(null);
        }
        if (record.getGzsjd6().equals("")){
            record.setGzsjd6(null);
        }
        if(record.getSixrq1().equals("")){
            record.setSixrq1(null);
        }
        if(record.getSixrq2().equals("")){
            record.setSixrq2(null);
        }
        if(record.getSixrq3().equals("")){
            record.setSixrq3(null);
        }

        if(record.getSixdate1().equals("")){
            record.setSixdate1(null);
        }
        if(record.getSixdate2().equals("")){
            record.setSixdate2(null);
        }
        if(record.getSixdate3().equals("")){
            record.setSixdate3(null);
        }
        if (record.getJlrrq().equals("")){
            record.setJlrrq(null);
        }
        if (record.getXcxjyrq().equals("")){
            record.setXcxjyrq(null);
        }
        if(record.getDate1().equals("")){
            record.setDate1(null);
        }
        return new SimpleCoreResponse("200","成功修改数据",hcCupweldingrecordService.updateById(record));
    }

    @RequestMapping("queryRecord")
    public SimpleCoreResponse queryRecord() throws AdscmSystemException {
        return new SimpleCoreResponse("200","成功查询数据",hcCupweldingrecordService.selectList(null));
    }

    @RequestMapping("queryRecordById")
    public SimpleCoreResponse queryRecordById(String id, HttpServletResponse response) throws AdscmSystemException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        return new SimpleCoreResponse("200","成功根据查询单条记录数据",hcCupweldingrecordService.selectById(id));
    }


}

